<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>属性的基本操作</title>
</head>
<body>
    <script>
        let user = {
            name : 'xiasnn',
            "my age" : 18
        };

        // 一般使用.
        console.log(user.name);
        // 如果名字特殊，用括号
        console.log(user["my age"]);


        let arr = [1,2,3,4,5];
        for (const key in arr) {
            // 这个时候要用括号
            console.log(arr[key]);
        }


        // 添加属性
        user.age = 22;
        user['sex'] = '女';
        user.show = function(){
            return `${this.name}的年龄是${this.age}`;
        };
        console.log(user.show());
        console.log(user);

        // 删除属性
        delete user.age;
        console.log(user);

        // 检测是否存在某个属性
        console.log(user.hasOwnProperty('age'));
        console.log(user.hasOwnProperty('sex'));
    </script>
</body>
</html>